package com.wowangz.cms.systemmanage.currency.service;

import java.util.HashMap;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Strings;
import com.wowangz.cms.syscore.exception.ServiceException;
import com.wowangz.cms.syscore.service.BaseService;
import com.wowangz.cms.systemmanage.currency.pojo.Currency;

public class CurrencyService extends BaseService {

	private Logger logger = LoggerFactory.getLogger(CurrencyService.class);

	public void add(Currency currency) throws ServiceException {
		this.getSqlSession().insert("Currency.insertCurrency", currency);
	}

	public void delete(String ids) throws Exception {
		if (Strings.isNullOrEmpty(ids)) {
			return;
		}
		String[] temIds = ids.split(",");

		for (String id : temIds) {
			this.getSqlSession().delete("Currency.deleteCurrency", id);
		}
	}

	public void update(Currency currency) throws ServiceException {
		this.getSqlSession().update("Currency.updateCurrency", currency);
	}
	
	public void updateAllCurrencyposition(Long currencyposition)throws ServiceException{
		this.getSqlSession().update("Currency.updateAllCurrencyposition", currencyposition);
	}

	public Currency findCurrencyById(String id) throws ServiceException {
		Currency currency = this.getSqlSession().selectOne("Currency.findCurrencyById", id);
		return currency;
	}

	public List<Currency> query(Currency currency) throws ServiceException {
		List<Currency> list = this.getSqlSession().selectList("Currency.queryCurrency");
		return list;

	}
	
	public boolean validationCurrency(HashMap<String, Object> map) throws ServiceException {
		Long countNum = this.getSqlSession().selectOne("Currency.validationCurrency", map);
		if(countNum != 0){
			return false;
		}else{
			return true;
		}
	}

	/**
	 * 分页查询总条数
	 * 
	 * @param map
	 * @return
	 */
	public long findResultCount(HashMap<String, Object> map) throws ServiceException {
		Long countNum = this.getSqlSession().selectOne("Currency.queryCurrencyCount", map);
		return countNum;
	}

	/**
	 * 查询记录集合
	 * 
	 * @param map
	 * @return
	 */
	public List<Currency> findResultList(HashMap<String, Object> map) throws ServiceException {
		List<Currency> list = this.getSqlSession().selectList("Currency.queryCurrencyPage", map);
		System.out.println("123");
		return list;
	}

}
